package com.android.handset;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.content.pm.PackageManager;

import androidx.core.app.ActivityCompat;

/**
 * 蓝牙管理类
 */
public class BluetoothController {
	private BluetoothAdapter mAdapter;

	public BluetoothController() {
		mAdapter = BluetoothAdapter.getDefaultAdapter();
	}

	/**
	 * 判断当前设备是否支持蓝牙
	 * @return
	 */
	public boolean isSupportBluetooth() {
		if (mAdapter != null) {
			return true;
		}
		return false;
	}

	/**
	 * 获取蓝牙的状态
	 * @return
	 */
	public boolean getBluetoothStatus() {
		if (mAdapter != null) {
			return mAdapter.isEnabled();
		}
		return false;
	}

	/**
	 * 打开蓝牙
	 * @param activity
	 * @param requestCode
	 */
	public void turnOnBluetooth(Activity activity, int requestCode) {
		if (mAdapter != null && !mAdapter.isEnabled()) {
			Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
			activity.startActivityForResult(intent, requestCode);
		}
	}

	/**
	 * 关闭蓝牙
	 */
	public void turnOffBluetooth() {
		if (mAdapter != null && mAdapter.isEnabled()) {

			mAdapter.disable();
		}
	}

}